<template>
  <div class="preview-demo">
    <div class="demo-header">
      <h1>简历预览功能演示</h1>
      <p>支持PDF、Word文档、图片等多种格式的在线预览</p>
    </div>

    <div class="demo-content">
      <el-row :gutter="24">
        <el-col :span="8" v-for="demo in demoFiles" :key="demo.id">
          <el-card class="demo-card" shadow="hover">
            <div class="card-header">
              <h3>{{ demo.title }}</h3>
              <el-tag :type="demo.tagType" size="small">{{ demo.type }}</el-tag>
            </div>
            <div class="card-content">
              <p>{{ demo.description }}</p>
              <div class="file-info">
                <span class="file-name">{{ demo.fileName }}</span>
                <span class="file-size">{{ demo.fileSize }}</span>
              </div>
            </div>
            <div class="card-actions">
              <el-button 
                type="primary" 
                @click="previewFile(demo)"
                :icon="View"
              >
                预览
              </el-button>
              <el-button 
                @click="downloadFile(demo)"
                :icon="Download"
              >
                下载
              </el-button>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 预览对话框 -->
    <EnhancedResumePreview
      v-model:visible="showPreview"
      :file-url="currentFile.url"
      :file-name="currentFile.fileName"
      :title="currentFile.title"
      @download="handleDownload"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { View, Download } from '@element-plus/icons-vue'
import EnhancedResumePreview from '@/components/EnhancedResumePreview.vue'

// 演示文件数据
const demoFiles = ref([
  {
    id: 1,
    title: 'PDF简历示例',
    type: 'PDF文档',
    tagType: 'danger',
    description: '标准PDF格式简历，支持多页面浏览和缩放功能',
    fileName: '张三-前端工程师简历.pdf',
    fileSize: '2.3 MB',
    url: '/demo/resume-sample.pdf'
  },
  {
    id: 2,
    title: 'Word简历示例',
    type: 'Word文档',
    tagType: 'primary',
    description: '在线生成的Word格式简历，支持完整的文档预览',
    fileName: '李四-后端工程师简历.docx',
    fileSize: '1.8 MB',
    url: '/demo/resume-sample.docx'
  },
  {
    id: 3,
    title: '图片简历示例',
    type: '图片文件',
    tagType: 'success',
    description: '图片格式的简历，支持高清预览和缩放',
    fileName: '王五-设计师简历.png',
    fileSize: '3.2 MB',
    url: '/demo/resume-sample.png'
  },
  {
    id: 4,
    title: '文本简历示例',
    type: '文本文件',
    tagType: 'info',
    description: '纯文本格式的简历，适合程序员使用',
    fileName: '赵六-程序员简历.txt',
    fileSize: '15 KB',
    url: '/demo/resume-sample.txt'
  },
  {
    id: 5,
    title: 'Markdown简历',
    type: 'Markdown文件',
    tagType: 'info',
    description: 'Markdown格式的技术简历，支持语法高亮',
    fileName: '孙七-技术专家简历.md',
    fileSize: '25 KB',
    url: '/demo/resume-sample.md'
  },
  {
    id: 6,
    title: 'Excel简历示例',
    type: 'Excel文件',
    tagType: 'warning',
    description: '表格形式的简历，不支持在线预览',
    fileName: '周八-数据分析师简历.xlsx',
    fileSize: '1.2 MB',
    url: '/demo/resume-sample.xlsx'
  }
])

// 当前预览文件
const showPreview = ref(false)
const currentFile = ref({
  url: '',
  fileName: '',
  title: ''
})

// 预览文件
const previewFile = (file: any) => {
  currentFile.value = {
    url: file.url,
    fileName: file.fileName,
    title: `预览 - ${file.title}`
  }
  showPreview.value = true
}

// 下载文件
const downloadFile = (file: any) => {
  // 模拟下载
  ElMessage.success(`开始下载: ${file.fileName}`)
  
  // 实际项目中这里应该是真实的下载逻辑
  const link = document.createElement('a')
  link.href = file.url
  link.download = file.fileName
  link.target = '_blank'
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
}

// 处理预览下载
const handleDownload = () => {
  downloadFile({
    url: currentFile.value.url,
    fileName: currentFile.value.fileName
  })
}
</script>

<style lang="scss" scoped>
.preview-demo {
  padding: 24px;
  background: #f5f7fa;
  min-height: 100vh;
}

.demo-header {
  text-align: center;
  margin-bottom: 40px;
  
  h1 {
    font-size: 32px;
    color: #2c3e50;
    margin-bottom: 12px;
    font-weight: 600;
  }
  
  p {
    font-size: 16px;
    color: #7f8c8d;
    margin: 0;
  }
}

.demo-content {
  max-width: 1200px;
  margin: 0 auto;
}

.demo-card {
  margin-bottom: 24px;
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  }
  
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    
    h3 {
      margin: 0;
      font-size: 18px;
      color: #2c3e50;
      font-weight: 600;
    }
  }
  
  .card-content {
    margin-bottom: 20px;
    
    p {
      color: #7f8c8d;
      line-height: 1.6;
      margin-bottom: 12px;
    }
    
    .file-info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 12px;
      background: #f8f9fa;
      border-radius: 6px;
      
      .file-name {
        font-size: 14px;
        color: #495057;
        font-weight: 500;
      }
      
      .file-size {
        font-size: 12px;
        color: #6c757d;
        background: #e9ecef;
        padding: 2px 8px;
        border-radius: 12px;
      }
    }
  }
  
  .card-actions {
    display: flex;
    gap: 12px;
    
    .el-button {
      flex: 1;
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .demo-content {
    :deep(.el-col) {
      width: 100%;
      margin-bottom: 16px;
    }
  }
  
  .demo-header {
    h1 {
      font-size: 24px;
    }
    
    p {
      font-size: 14px;
    }
  }
}
</style>
